//图片加载前用随机色渲染
Vue.directive('img-lazy-load', {
    // 当被绑定的元素插入到 DOM 中时……
    inserted: function (el, binding) {
        var color = Math.floor(Math.random() * 1000000);
        el.style.backgroundColor = "#" + color;




        var img = new Image();
        img.src = binding.value;
        img.onload = function () {
            el.style.background = "url(" + "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1512130636119&di=ad6017afe8acd3a305806b638c43bb93&imgtype=0&src=http%3A%2F%2Fi1.hdslb.com%2Fbfs%2Fface%2Fdd2336fbbb9b976179eae07fb0eaa66e0c5f34b1.gif" + ") no-repeat center center"
        }

        setTimeout(() => {
            var img = new Image();
            img.src = binding.value;
            img.onload = function () {
                el.style.backgroundImage = "url(" + binding.value + ")"
            }
        }, 1000);


    }
});
